package com.jrtc.backend.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.base.Strings;
import com.jrtc.base.config.dto.ResultDTO;
import com.jrtc.base.config.dto.ResultDTOBuilder;
import com.jrtc.base.entity.bo.ArticulusReport;
import com.jrtc.base.entity.bo.Case;
import com.jrtc.base.entity.vo.ArticulusReportVo;
import com.jrtc.service.ArticulusReportService;
import com.jrtc.service.CaseService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("case")
public class CaseController {
    /**
     * 服务对象
     */
    @Resource
    private CaseService caseService;

    /**
     * 病例列表
     * */
    @PostMapping("/caseList")
    public ResultDTO caseList(HttpServletRequest request, @RequestBody Map<String, Long> map){
        IPage<Case> caseList;
        try {
            Long pageNo = map.get("pageNo");
            Long pageSize = map.get("pageSize");
            caseList = caseService.caseList(pageNo, pageSize, request);
        } catch (Exception e){
            return ResultDTOBuilder.failureMsg(e.getMessage());
        }

        return ResultDTOBuilder.success(caseList);
    }

    /**
     * 编辑病例
     * */
    @PostMapping("/insertCase")
    public ResultDTO insertCase(HttpServletRequest request, @RequestBody Case c){
        int i;
        try {
            i = caseService.insertCase(c, request);
        } catch (Exception e){
            return ResultDTOBuilder.failureMsg(e.getMessage());
        }
        if (i > 0){
            return ResultDTOBuilder.success("保存成功");
        }
        else {
            return ResultDTOBuilder.failureMsg("保存失败");
        }
    }
}